/*

	This files collects the output from the De Loecker et al. (2016) procedure

*/

cd ${work}4_reg_variables

use input\estimationfile, clear
keep fid pcode12 unit year fup12 pnic2 sv q_j lmu_x lmc_x n theta_fjt_x theta_L_fjt_x theta_K_fjt_x pnic4

merge 1:1 fup12 year using input\rhos, assert(1 3) keepusing(rho_x exit_x) nogen
drop fup12

replace rho_x = 1 if n==1
drop n

rename fid		jurnr_num
rename pcode12	vnr
rename pnic2	section
rename sv		sales_ipt
rename q_j		log_quantity
rename lmu_x	log_mu
rename lmc_x	log_mc
rename rho_x	rho
rename theta_fjt_x 		theta_m
rename theta_L_fjt_x 	theta_l
rename theta_K_fjt_x	theta_k

gen cn2=floor(pnic4/100)
drop pnic4

replace sales = sales * 1e3

save output\vars_ipt, replace